import requests

from common.config import getconf
from tests.new_rypark_background.get_cookie import internal_token


class ParkingGarage:
    # =====================车库管理=====================

    def create_parking_garage(self, env, capacity=0, payChannels="", enterParkingLotConfig=[],floor='10'):
        """创建车库"""
        base_url = getconf(env, "zhongtai_url")
        url = base_url + "platform-parking-server/parkingGarage/create"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "token": internal_token(env)}
        dict = {
            "name": "自动化测试新建车库",
            "location": "上海市浦东新区申江路5005弄",
            "floor": floor,
            "capacity": capacity,
            "feeDesc": "500个字最多",
            "parentId": "",
            "payChannels": payChannels,  # "weixinpay,alipay"
            "feeConfiguration": "",
            "enterParkingLotConfig": enterParkingLotConfig,
            "parkingLotId": getconf(env, "parking_lot_id")
        }
        return requests.post(url, headers=headers, json=dict).json()

    def query_parking_garage_list(self, env, name="",parkingLotId=-1, parkingGarageType=1, current=1, size=12):
        """车库列表"""
        base_url = getconf(env, "zhongtai_url")
        url = base_url + "platform-parking-server/parkingGarage/list/page"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "token": internal_token(env)}
        dict = {
            "name": name,
            "parkingLotId": parkingLotId,
            "parkingGarageType": parkingGarageType,  # 1-外库 2-内库
            "current": current,
            "size": size
        }
        return requests.post(url, headers=headers, json=dict).json()

    def update_parking_garage(self, env, id, capacity=0, payChannels="",floor='0', enterParkingLotConfig=[]):
        base_url = getconf(env, "zhongtai_url")
        url = base_url + "platform-parking-server/parkingGarage/update"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "token": internal_token(env)}
        dict = {
            "id": id,
            "name": "自动化测试新建车库",
            "location": "上海市浦东新区申江路5005弄",
            "floor": floor,
            "capacity": capacity,
            "feeDesc": "500个字最多",
            "parentId": "",
            "payChannels": payChannels,  # "weixinpay,alipay"
            "feeConfiguration": "",
            "enterParkingLotConfig": enterParkingLotConfig,
            "parkingLotId": getconf(env, "parking_lot_id")
        }
        return requests.post(url, headers=headers, json=dict).json()

    def garage_watchkeeper_auth(self, env, garage_id):
        """员工授权"""
        base_url = getconf(env, "zhongtai_url")
        url = base_url + "platform-parking-server/parkingGarage/watchkeeper/list/"+garage_id
        headers = {"content-type": "application/json;charset=UTF-8",
                   "token": internal_token(env)}
        return requests.get(url, headers=headers).json()



